$(function () {
    //密码输入框type转换
    let display = true,
        disCons = true;
    $('.passDis').click(() => {
        if (display) {
            $('.passDis').attr("src", "../../images/disblock.png");
            $('.password').attr("type", "text");
        } else {
            $('.passDis').attr("src", "../../images/disnone.png");
            $('.password').attr("type", "password");
        }
        display = !display
    });
    $('.conpassword').click(() => {
        if (disCons) {
            $('.conpassword').attr("src", "../../images/disblock.png");
            $('.passCons').attr("type", "text");
        } else {
            $('.conpassword').attr("src", "../../images/disnone.png");
            $('.passCons').attr("type", "password");
        }
        disCons = !disCons
    });

//账号类型
    $("input[name='identity']").click(() => {
        let identityRole = $("input[name='identity']:checked").val()
        if (identityRole == 0) {
            $('.inf-tips').css("display", "block")
            $('.tips-error').html('用户可发布以及管理投票项目但不可参与投票');
        } else if (identityRole == 1) {
            $('.inf-tips').css("display", "block")
            $('.tips-error').html('管理员可发布以及管理投票项目但不可参与投票');

        }
        sessionStorage.setItem("roleKey", identityRole);
    })


    //提交数据
    $('.registJump').click(() => {
        let userName = $('.username').val(), //用户名
            passWord = $('.password').val(), //密码
            passCons = $('.passCons').val(), // 确认密码
            role = sessionStorage.getItem("roleKey");
        if (userName == "" || passWord == "" || passCons == "") {
            $('.inf-error').html('输入内容不能为空');
            $('.inf-body').css('display', "block");
        } else if (!/^[0-9a-zA-Z]{8,10}$/.test(passWord)) {
            $('.inf-error').html('密码长度不小于8位大于10位');
            $('.inf-body').css('display', "block");
        } else if (passWord != passCons) {
            $('.inf-error').html('密码与确认密码不符');
            $('.inf-body').css('display', "block");
        } else if (role == null) {
            $('.inf-error').html('选择账户类型');
            $('.inf-body').css('display', "block");
        } else {
            let register;
            register = Interceptor('/register', 'post', {
                "userName": userName,
                "password": passWord,
                "rePassword": passCons,
                "role": role
            })
            switch (register.code) {
                case 4000:
                    $('.inf-error').html('用户名或密码填写错误，请重试');
                    $('.inf-body').css('display', "block");
                    break;
                case 200:
                    $('.inf-body').css('display', "none");
                    userName = ""
                    passWord = ""
                    passCons = ""
                    sessionStorage.removeItem("roleKey");
                    $('.registJump').attr("href", "login.html");
            }
        }

    })
})

